;(function (global){ 
	var CGI = {
			PROMOTION_LINK_ADD: window.frontPath + 'promotionLink/saveProLink',//查询历史记录
			PROMOTION_LINK_UPDATE: window.frontPath + 'promotionLink/updateProLink'//查询历史记录
	}; 
	
	jQuery(function()
			{ 
		       var minRebate =parseFloat(jQuery("#fandianSelect").attr("minRebate"));
		       var maxRebate=parseFloat(jQuery("#fandianSelect").attr("maxRebate"));
		       var dc = parseFloat(jQuery("#fandianSelect").attr("dc"));
		       var userRebate=jQuery("#fandianSelect").attr("userRebate");
		       for(var i=maxRebate;i>=minRebate-dc;i-=dc)
		       { 
		    	  if(userRebate&&parseInt(userRebate*1000)==parseInt(i*1000))
		    	  {
		    		  jQuery("<option value='"+Math.abs(i).toFixed(4)+"' selected>"+Math.abs(i*100).toFixed(1)+"%</option>").appendTo("#fandianSelect");
		    	  }
		    	  else
		    	  {
		    		  jQuery("<option value='"+Math.abs(i).toFixed(4)+"' >"+Math.abs(i*100).toFixed(1)+"%</option>").appendTo("#fandianSelect");
		    	  }
		       }
			});
	
      jQuery("#savePromBtn").click(function()
      {
    	   var promotionLinkName = jQuery("input[name='promotionLinkName']");
    	   if(jQuery.trim(jQuery(promotionLinkName).val())==""||
    		  jQuery.trim(jQuery(promotionLinkName).val())==jQuery.trim(jQuery(promotionLinkName).attr("data-placeholder")))
    	   {
    		    jQuery(promotionLinkName).select();
    			return $.alert({
    	    		status : 'error',
    				basicTitle : '请输入推广名称!'
    			});   
    	   }
   		  $.ajax({
			url 	: CGI.PROMOTION_LINK_ADD,
			method 	: 'POST',
			data    : {
				userType: $('input[name="userType"]:checked').val(),
				promotionLinkName: jQuery(promotionLinkName).val(),
				userRebate: jQuery("#fandianSelect").val() 
			},
			success : function(data){
				if(0 === data.retcode){
		    		$.alert({
			    		status : 'ok',
						basicTitle : '添加成功！'
					});
		    		window.setTimeout(function (){
		    			$.none_alert(function (){
		    				window.location.href = window.frontPath+ 'home#/promotionLink/main';
		    			});
		    		},2000);
		    	}else{
		    		$.exception(data.retcode , data.retmsg);
		    	}
			}
		  });
      }		 
     );
      
      
      jQuery("#updatePromBtn").click(function()
    	      {
    	    	   var promotionLinkName = jQuery("input[name='promotionLinkName']");
    	    	   if(jQuery.trim(jQuery(promotionLinkName).val())==""||
    	    		  jQuery.trim(jQuery(promotionLinkName).val())==jQuery.trim(jQuery(promotionLinkName).attr("data-placeholder")))
    	    	   {
    	    		    jQuery(promotionLinkName).select();
    	    			return $.alert({
    	    	    		status : 'error',
    	    				basicTitle : '请输入推广名称!'
    	    			});   
    	    	   }
    	   		  $.ajax({
    				url 	: CGI.PROMOTION_LINK_UPDATE,
    				method 	: 'POST',
    				data    : {
    					userType: $('input[name="userType"]:checked').val(),
    					promotionLinkName: jQuery(promotionLinkName).val(),
    					userRebate: jQuery("#fandianSelect").val(),
    					id:jQuery("#promLinkId").val()
    				},
    				success : function(data){
    					if(0 === data.retcode){
    			    		$.alert({
    				    		status : 'ok',
    							basicTitle : '修改成功！'
    						});
    			    		window.setTimeout(function (){
    			    			$.none_alert(function (){
    			    				window.location.href = window.frontPath+ 'home#/promotionLink/main';
    			    			});
    			    		},2000);
    			    	}else{
    			    		$.exception(data.retcode , data.retmsg);
    			    	}
    				}
    			  });
    	      }		 
    	     );

})(window);